package com.vecspace.dayu.code.httphandler;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

import com.vecspace.dayu.code.pojo.ProjectUser;
import com.vecspace.dayu.code.service.ProjectUserService;
import com.vecspace.security.model.LoginContext;
import com.vecspace.web.servlet.model.BaseController;
import com.vecspace.web.servlet.model.HController;
import com.vecspace.web.servlet.model.Param;
import com.vecspace.web.servlet.model.Path;

/** DAYU-项目用户。暂不验证密码，输入用户名即可进入,loginId与oa里面的loginId保持一致。以后可考虑同步OA httphandler
 * 在handler中进行与页面相关的处理，比如把数据转换为HTML格式等。
 * @author wanghua
 * @reviewer
 * @template wanghua
*/
@HController("dayucode_projectUserHandler")
public class ProjectUserHandler extends BaseController {

	/**根据ID查询 DAYU-项目用户。暂不验证密码，输入用户名即可进入,loginId与oa里面的loginId保持一致。以后可考虑同步OA
	 * @return ProjectUser
	 * @throws Exception
	 * @author wanghua
	 */
	@Path("getProjectUser")
	public ProjectUser getProjectUser(@Param("id") Long id) throws Exception {
		return projectUserService.getProjectUser(id);
	}
	
	/**获取项目中的所有用户
	 * 
	 * @param projectId
	 * @return
	 * @throws Exception 
	 * @author wanghua
	 */
	@Path("getProjectUsers")
	public List<ProjectUser> getProjectUsers(@Param("projectId")Long projectId) throws Exception {
		return projectUserService.getProjectUsers(projectId);
	}
	
	/**添加超级管理员
	 * 
	 * @param userId  要增加为超级管理员的用户的id
	 * @param loginId 当前登录用户的id
	 * @return
	 * @throws Exception 
	 * @author wanghua
	 */
	@Path("addSuperAdmin")
	public ProjectUser addSuperAdmin(@Param("userId")String userId) throws Exception {
		String loginId = LoginContext.getLoginId();
		return projectUserService.addSuperAdmin(userId, loginId);
	}
	
	/**添加项目成员
	 * 
	 * @param userId  要增加为项目超级管理员的用户的id
	 * @param projectId 项目id
	 * @param isProjectAdmin 是否项目管理员
	 * @param loginId 当前登录用户的id
	 * @return
	 * @throws Exception 
	 */
	@Path("addProjectUser")
	public ProjectUser addProjectUser(@Param("userId")String userId, @Param("projectId")Long projectId, @Param("isProjectAdmin")boolean isProjectAdmin) throws Exception {
		String loginId = LoginContext.getLoginId();		
		return projectUserService.addProjectUser(userId, projectId, isProjectAdmin, loginId);		
	}
	
	/**项目用户变更为项目管理员
	 * 
	 * @param projectUserId
	 * @return
	 * @throws Exception 
	 * @author wanghua
	 */
	@Path("changeProjectAdmin")
	public ProjectUser changeProjectAdmin(@Param("projectUserId")Long projectUserId, @Param("isProjectAdmin")boolean isProjectAdmin) throws Exception {
		String loginId = LoginContext.getLoginId();
		ProjectUser projectUser = projectUserService.changeProjectAdmin(projectUserId, isProjectAdmin, loginId);		
		return projectUser;
	}
	
	/** 根据ID删除 DAYU-项目用户。暂不验证密码，输入用户名即可进入,loginId与oa里面的loginId保持一致。以后可考虑同步OA 
	 * @param id	主键值
	 * @return void
	 * @throws Exception
	 * @author wanghua
	 */
	@Path("deleteProjectUser")
	public void deleteProjectUser(@Param("id") Long id) throws Exception {
		projectUserService.deleteProjectUser(id);
	}

	/************* property ********************/
	@Autowired
	private ProjectUserService projectUserService;

}
